#!/usr/bin/env bash
commonFile="./common/models/$2.php"
adminFile="./apps/admin/models/$2.php"
homeFile="./apps/home/models/$2.php"
./yii gii/model --ns="common\\models" --generateLabelsFromComments=1 --useTablePrefix=1 --tableName=$1 --modelClass=$2
if [ ! -f $adminFile ]; then
    cp $commonFile $adminFile
    sed -i "" -e "/^ \* .*/d" -e "/^ \*$/c * {@inheritdoc}" -e '3s/common/admin/g' -e "s/\\\yii\\\db\\\ActiveRecord/\\\common\\\models\\\\$2/g" -e "/    /d" $adminFile
fi
if [ ! -f $homeFile ]; then
    cp $commonFile $homeFile
    sed -i "" -e "/^ \* .*/d" -e "/^ \*$/c * {@inheritdoc}" -e '3s/common/home/g' -e "s/\\\yii\\\db\\\ActiveRecord/\\\common\\\models\\\\$2/g" -e "/    /d" $homeFile
fi
